﻿using System;

namespace Borg.AttributeAnalyze.Result
{
    public class MissingSlotDefinition : ResultBase
    {
        private readonly PlugTypeInfo _plug;
        private readonly SlotTypeInfo _slot;

        public MissingSlotDefinition(PlugTypeInfo plug)
            : base(plug.Assembly, Component.Plug, ResultType.MissingSlotDefinition, plug, plug.ExtensionTypeInfo)
        {
            _plug = plug;
            RepositoryElement = plug;
            ExtensionTypeInfo = plug.ExtensionTypeInfo;
        }

        public MissingSlotDefinition(SlotTypeInfo slot)
            : base(slot.Assembly, Component.Slot, string.IsNullOrWhiteSpace(slot.DerivedFrom)
                ? ResultType.MissingSlotDefinition
                : ResultType.MissingDerivedSlotDefinition, slot, slot.ExtensionTypeInfo)
        {
            _slot = slot;
            RepositoryElement = slot;
            ExtensionTypeInfo = slot.ExtensionTypeInfo;
        }

        public override string ToMsBuildMessageString()
        {
            if (Result == ResultType.MissingSlotDefinition)
                return string.Format(
                    "no slotdefinition found\n{0}slot name: {1}\n{0}class: {2}",
                    GetWhiteSpace(2), Name, TypeName);

            if (Result != ResultType.MissingDerivedSlotDefinition)
                throw new NotImplementedException();

            return string.Format(
                "no slotdefinition found\n{0}slot name: {1}\n{0}derived from slot {2}\n{0}class: {3}",
                new object[] { GetWhiteSpace(2), Name, _slot.DerivedFrom, TypeName });
        }

        public override MessageType MessageType
        {
            get { return MessageType.Error; }
        }
    }
}

